//
//  FSReadRecordController.m
//  Trade
//
//  Created by 刘沿 on 16/4/11.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSReadRecordController.h"
#import "FSRecordListCell.h"


@interface FSReadRecordController ()

@property (strong, nonatomic) IBOutlet UIView *meetIngPeopleListHeaderView;

@property (strong, nonatomic) IBOutlet UIView *psjHeaderView;

@property (strong, nonatomic) IBOutlet UIView *meetingHeaderView;

@property (strong, nonatomic) IBOutlet UIView *headerView;

@property(strong,nonatomic)NSMutableArray * contentsArray;


@end

@implementation FSReadRecordController

-(NSMutableArray*)contentsArray{
    if (_contentsArray == nil) {
        _contentsArray  = [NSMutableArray array];
    }
    return _contentsArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self requestData];
    
}

-(void)requestData{
    NSString * method = nil;
    if ([self.exchangeForm isEqualToString:@"form_meeting"]) {
        if (self.isMeetingList) {
//会议名单
            method =  KMeetNamelistMethod;
        }else{
//  签收记录
            method = KSignInMeetRecord;
        }
        
    }else{
        if ([self.exchangeForm isEqualToString:@"form_psj"] && self.isFromPSJType) {
            method = KInstructionsNamelist;
        }else{
            method =  KSignInRecord;
        }
        
    }
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"unid":self.identifier},@{@"userId":userId}];
    __weak typeof(self) weakSelf = self;
    [HttpTools requestWithURL:KexchangeRecord arrays:array method:method success:^(id JSON) {
        
        
        if ([JSON[@"data"] isKindOfClass: [NSArray class]]) {
            self.contentsArray = JSON[@"data"];
        }
        
        [weakSelf.tableView reloadData];
        if ([weakSelf.exchangeForm isEqualToString:@"form_meeting"]) {
            
            if (self.isMeetingList) {
                weakSelf.meetIngPeopleListHeaderView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 64);
                weakSelf.tableView.tableHeaderView = weakSelf.meetIngPeopleListHeaderView;
            }else{
                
                weakSelf.meetingHeaderView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 64);
                weakSelf.tableView.tableHeaderView = weakSelf.meetingHeaderView;
            }
            
            
        }else{
            if ([self.exchangeForm isEqualToString:@"form_psj"] && self.isFromPSJType){
                weakSelf.psjHeaderView.frame = CGRectMake(0, 0, weakSelf.view.bounds.size.width, 64);
                weakSelf.tableView.tableHeaderView = weakSelf.psjHeaderView;
                
            }else{
                weakSelf.headerView.frame = CGRectMake(0, 0, weakSelf.view.bounds.size.width, 64);
                weakSelf.tableView.tableHeaderView = weakSelf.headerView;
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contentsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FSRecordListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"recordIdentifier" forIndexPath:indexPath];
    NSDictionary * dict = self.contentsArray[indexPath.row];
    if ([self.exchangeForm isEqualToString:@"form_meeting"]) {
        
        if (self.isMeetingList) { //参会人员
            
            cell.subjectFirst.text = dict[@"unit"];
            cell.subjectSecond.text = dict[@"name"];
            cell.subjectThird.text = dict[@"post"];
            cell.subjectFour.text = dict[@"telephone"];
            cell.subjectFive.text = dict[@"demo"];
            
        }else{ // 阅读记录
            cell.subjectFirst.text = dict[@"unit"];
            cell.subjectSecond.text = dict[@"participants"];
            cell.subjectThird.text = dict[@"signtime"];
            cell.subjectFour.text = dict[@"reportingtime"];
            cell.subjectFive.text = dict[@"handle"];
        }
        
        
    }else{
        if ([self.exchangeForm isEqualToString:@"form_psj"] && self.isFromPSJType){ //批示件回复
            
            cell.subjectFirst.text = dict[@"unit"];
            cell.subjectSecond.text = dict[@"secretaryResponsibleperson"];
            cell.subjectThird.text = dict[@"departmentResponsibleperson"];
            cell.subjectFour.text = dict[@"bureauapproval"];
            cell.subjectFive.text = dict[@"reportingtime"];
            
        }else{ //阅读记录
            cell.subjectFirst.text = dict[@"company"];
            cell.subjectSecond.text = dict[@"opinion"];
            cell.subjectThird.text = dict[@"signtime"];
            cell.subjectFour.text = dict[@"recoverytime"];
            cell.subjectFive.text = dict[@"handle"];
        }
        
    }
    
    return cell;
    
}

@end






